var http = require('http');


var server = http.createServer(function(req, res) {
	handle(req, res);
});

server.listen(8080, '127.0.0.1');
console.log('server start...');

var rpcClient = null;
server.type = 'authorHttp';

function handle(req, res) {
	if (!rpcClient) {
		return res.end('rpcClient not ready');
	}

	rpcClient.rpc('book', 'hello,i am author', function(result) {
		console.log(result);
		res.end(result.toString());
	});
}

var __type = 'author';
var wrapper = require('./wrapper.js');
wrapper.init(__type, handle, function(err, rpcWrapper) {
	if (err) console.log(err);
	else {
		rpcClient = rpcWrapper;
		console.log('%s ok', __type);
	}
});